package find.chat.test;

import java.io.UnsupportedEncodingException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
import android.content.Intent;
import android.os.Handler;
import android.test.suitebuilder.annotation.SmallTest;
import find.chat.*;
import find.chat.R;
import find.chat.interfaces.IAppManager;
import find.chat.services.IMService;
import find.chat.tools.FriendController;
import find.chat.types.FriendInfo;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;
import android.test.TouchUtils;
import android.test.ActivityInstrumentationTestCase2;

public class unapprovedfriendlist extends ActivityInstrumentationTestCase2<UnApprovedFriendList> {
	private UnApprovedFriendList mActivity;
/*	ListView friend_list;
	View viewToClick;
*/
	public unapprovedfriendlist() {
		super(UnApprovedFriendList.class);
	}

	protected void setUp() throws Exception {
		// this method is called every time before any test execution
		super.setUp();
		
		FriendInfo[] unApprovedFriends = null;
		Intent addFriendsInfo = new Intent();
		String tmp = new String();
		
		unApprovedFriends = FriendController.getUnapprovedFriendsInfo();
		
		if (unApprovedFriends.length > 0)
		{
			for (int j = 0; j < unApprovedFriends.length; j++) {
				tmp = tmp.concat(unApprovedFriends[j].userName).concat(",");			
			}
			addFriendsInfo.putExtra(FriendInfo.FRIEND_LIST, tmp);
		}
		setActivityIntent(addFriendsInfo);

		mActivity = (UnApprovedFriendList) getActivity(); // get current activity
		Thread loginThread = new Thread(){
			@Override
			public void run() {
				String result = null;
				try {
					result =  mActivity.imService.authenticateUser("chung","12345");
				} catch (UnsupportedEncodingException e) {
					
					e.printStackTrace();
				}
			}			
		};
		loginThread.start();
		// link the objects with the activity objects
	}

	@SmallTest
	// SmallTest: this test doesn't interact with any file system or network.
	public void testView() { // checks if the activity is created
		assertNotNull(getActivity());
	}
	public void testDiscardRequest()
	{
		mActivity.imService.addNewFriendRequest("test1","12345","chung");
		getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
		getInstrumentation().invokeMenuActionSync(mActivity, mActivity.APPROVE_SELECTED_FRIENDS_ID, 0);
		assertTrue(true);
	}
}
